package fightplan.actions;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;

import fightplan.business.Tournament;
import fightplan.persistence.OldImport;
import fightplan.views.MainView;

@SuppressWarnings("serial")
public class ImportOldFighterAction extends AbstractAction {

	private MainView mainView;

	public ImportOldFighterAction(MainView mainView) {
		super("Teilnehmer importieren");
		this.mainView = mainView;
	}

	public void actionPerformed(ActionEvent actionEvent) {
		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.setDialogTitle("Altes Turnier auswählen");
		fileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
			public boolean accept(File f) {
				return !f.isFile() || f.getName().endsWith(".trn");
			}

			public String getDescription() {
				return "TRN (Turnier) (*.trn)";
			}
		});
		if (fileChooser.showDialog(mainView, "Importieren") == JFileChooser.APPROVE_OPTION) {
			OldImport.imprt((Tournament) mainView.getTournament().getValue(), fileChooser.getSelectedFile());
		}
	}

}